package com.study.forumsystemproject.controller;

import com.study.forumsystemproject.common.Result;
import com.study.forumsystemproject.common.ResultCode;
import com.study.forumsystemproject.constant.Constants;
import com.study.forumsystemproject.model.Board;
import com.study.forumsystemproject.service.IBoardService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * program: forum-system-project
 * <p>
 * description: 版块控制层
 * <p>
 * author: xiaoxie
 * <p>
 * create: 2024-08-16 23:09
 **/
@RequestMapping("/board")
@RestController
@Slf4j
@Tag(name = "版块类测试API")
public class BoardController {

    @Autowired
    private IBoardService boardService;
    @Operation(summary = "获取版块测试API")
    @GetMapping("/getList")
    public Result<List<Board>> getBoardList() {
        List<Board> boards = boardService.getBoards(Constants.BOARD_NUM);
        if (boards == null || boards.isEmpty()) {
            log.warn(ResultCode.FAILED_NOT_EXISTS.toString());
            return Result.fail("获取列表失败,请刷新页面");
        }
        return Result.success(boards);
    }
}
